#include "string.h"


int main() {
	String str("apple");
	std::cout<<"str is: ";
	for(StringIterator strIter = str.begin(); strIter != str.end(); ++strIter){
	std::cout<< *strIter;
	} 
	std::cout<<std::endl;
#if 0
	//错误示范
	// 在字符串的第二个位置插入字符 'x'
	StringIterator it = str.begin();
	++it;
	str.insert(it, 'x');
	std::cout << "插入字符后: " << str << std::endl;
	
	// 使用新的 insert 接口，通过索引插入字符
	str.insert(1, 'h');
	std::cout << "使用新接口插入字符后: " << str << std::endl;
	
	std::cout<<*it<<std::endl;
	std::cout<<*(++it)<<std::endl;
	std::cout<<*(it++)<<std::endl;
	std::cout<<*it<<std::endl;
#endif
	// 在字符串的第二个位置插入字符 'x'
	StringIterator it = str.begin();
	++it;
	it = str.insert(it, 'x'); // 重新获取有效迭代器
	std::cout << "插入字符后: " << str << std::endl;
	
	// 使用新的 insert 接口，通过索引插入字符
	it = str.insert(1, 'h'); // 重新获取有效迭代器
	std::cout << "使用新接口插入字符后: " << str << std::endl;
	std::cout << *it << std::endl;
	++it;
	std::cout<<*it<<std::endl;
	++it;
	std::cout<<*it<<std::endl;
	++it;
	std::cout<<*it<<std::endl;
	++it;
	std::cout<<*it<<std::endl;
	--it;
	std::cout<<*it<<std::endl;
	std::cout<<*(it++)<<std::endl;
	std::cout<<*it<<std::endl;
	
	String str2(str);
	
	for(StringIterator strIter = str2.begin(); strIter != str2.end(); ++strIter){
		std::cout<< *strIter;
	} 
	std::cout<<std::endl;
	
	String str3("origin");
	str = str3;
	for(StringIterator strIter = str.begin(); strIter != str.end(); ++strIter){
		std::cout<< *strIter;
	} 
	std::cout<<std::endl;
	
	StringIterator it2 = str3.begin();
	StringIterator it3 = str2.begin();
	// 调用重载的 == 运算符进行比较
	if (it3 == it2) {
		std::cout << "两个迭代器相等" << std::endl;
	} else {
		std::cout << "两个迭代器不相等" << std::endl;
	}
	
	
	
	return 0;
}

